/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.upc.dew.proyecto.bd;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Tomas
 */

public class Conexion {
     private static final String URL =
            "jdbc:derby://localhost:1527/sample;user=app;password=app";

    public static Connection obtenerConexion(){
        Connection connection = null;
        try {
            Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
            connection = DriverManager.getConnection(URL);
//            connection.setCatalog("EXAMEN");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return connection;
        /*
        Connection con = null;
        try{
            DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
            con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "examen", "examen");
        } catch (SQLException ex){
            
        }
        return con;*/
    }

/*
public class Conexion {
    public static Connection obtenerConexion(){
        Connection con = null;
        try{
            //DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
            con = DriverManager.getConnection("jdbc:derby://localhost:1527/EXANEN");
        } catch (SQLException ex){

        }
        return con;
    }
 }*/
    public static void closeConnection(Connection connection) {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public static void closeStatement(Statement statement) {
        try {
            if (statement != null) {
                statement.close();
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public static void closeResultSet(ResultSet resultSet) {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
}


